﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace LD
{
    public partial class FrmPartNoEdit : Form
    {
        public FrmPartNoEdit()
        {
            InitializeComponent();
        }
        public FrmPartNoEdit(string name) : this()
        {
            var oPartNo = PartNoHelper.Instance.LoadPartNo(name);
            if (oPartNo != null)
            {
                this.txt_ccd.Text = oPartNo.CCDName;
                this.txt_screwId.Text = oPartNo.Id + "";
                this.txt_name.Text = oPartNo.Name;
            }
        }
        private void btn_save_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txt_ccd.Text)
                || string.IsNullOrEmpty(this.txt_name.Text)
                || string.IsNullOrEmpty(this.txt_screwId.Text)
                )
            {
                MessageBox.Show("值不能为空");
                return;
            }
            if (!int.TryParse(this.txt_screwId.Text, out var id))
            {
                MessageBox.Show("电批ID必须为整数类型");
                return;
            }
            Data = new PartNoModel
            {
                CCDName = this.txt_ccd.Text,
                Id = id,
                Name = this.txt_name.Text,
            };
            this.Close();
        }

        private void btn_cancal_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public PartNoModel Data { get; set; }
    }
}
